using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using VSSDKAssist.Assets.CustomPages;
using Microsoft.Practices.WizardFramework;
using VSSDKAssist.Assets.Converters;
using System.Globalization;

namespace VSSDKAssist.Recipes.CreateSolution
{
	/// <summary>
	/// Custom page for CreateSolutionCP1 recipe
	/// </summary>
	public partial class CreateSolutionCP1 : WizardPageBase
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="CreateSolutionCP1"/> class.
		/// </summary>
		public CreateSolutionCP1()
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="CreateSolutionCP1"/> class.
		/// </summary>
		/// <param name="wizard">The <see cref="T:Microsoft.Practices.WizardFramework.WizardForm"/>that will host the new page.</param>
		public CreateSolutionCP1(WizardForm wizard)
            : base(wizard)
        {
            InitializeComponent();
        }

		/// <summary>
		/// Gets or sets the name of the VS package project.
		/// </summary>
		/// <value>The name of the VS package project.</value>
		[RecipeArgument]
		public string VSPackageProjectName
		{
			get { return veProjectName.Value.ToString(); }
			set
			{
				if(value != null)
				{
					veProjectName.TextBox.Text = value;
				}
			}
		}

		/// <summary>
		/// Gets or sets the site of the control.
		/// </summary>
		/// <value></value>
		/// <returns>The <see cref="T:System.ComponentModel.ISite"></see> associated with the <see cref="T:System.Windows.Forms.Control"></see>, if any.</returns>
		/// <PermissionSet><IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence"/><IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/></PermissionSet>
		public override ISite Site
		{
			get
			{
				return base.Site;
			}
			set
			{
				base.Site = value;
				if(value != null)
				{
					this.veProjectName.BeginInit();
					this.veProjectName.ValueType = typeof(string);
					base.Site.Container.Add(veProjectName);
					this.veProjectName.ConverterInstance = new ValidFileNameConverter();
					this.veProjectName.EndInit();
				}
			}
		}

		private void veProjectName_ValueChanged(object sender, System.ComponentModel.Design.ComponentChangedEventArgs e)
		{
			if(veProjectName.ConverterInstance != null)
			{
				errorProvider.SetError(veProjectName, string.Empty);

				if(veProjectName.Value != null)
				{
					DictionaryService.SetValue("VSPackageProjectName", veProjectName.Value.ToString());
				}
				else
				{
					DictionaryService.SetValue("VSPackageProjectName", null);
					errorProvider.SetError(veProjectName, Properties.Resources.InvalidValue);
				}
			}
			else
			{
				DictionaryService.SetValue("VSPackageProjectName", veProjectName.Value.ToString());
			}
		}
	}
}